#include "Flee.h"
#include "Agent.h"
#include "Vec3.h"
#include <cmath>
#include "SteeringOutput.h"

namespace Engine
{
	Flee::Flee():m_fleeDist(0.0f), m_fleeDistSquared(0.0f){}
	
	void Flee::SetFleeDistance(float d)
	{
		m_fleeDist = d;
		m_fleeDistSquared = std::pow(d, 2.0f);
	}

	void Flee::Update(SteeringOutput* output)
	{
		output->linear = m_parent->GetPos() - m_target->GetPos();

		if(output->linear.SquaredLength() < m_fleeDistSquared)
		{
			output->linear.Normalize();
			output->linear *= m_parent->GetMaxSpeed();
		}
		else
			output->linear = Vec3();

		output->angular = 0;
	}
}